package com.pmcc.platform.giftGoods.web;

import com.pmcc.platform.giftGoods.service.GoodsDetailImageService;
import com.pmcc.platform.giftGoods.service.GoodsImageService;
import com.pmcc.platform.giftGoods.service.GoodsService;

import com.pmcc.platform.giftGoods.vo.GoodsVo;
import com.pmcc.utils.AntPage;
import com.pmcc.utils.ApiResultBean;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @program: vidalGift
 * @description: 赠品管理
 * @author: Du
 * @create: 2020-12-11 15:29
 **/
@RestController()
@RequestMapping("api/v1/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @Autowired
    GoodsImageService goodsImageService;

    @Autowired
    GoodsDetailImageService goodsDetailImageService;

    @Value("${qiNiu.accessKey}")
    private String accessKey;//公共配置文件路径

    @Value("${qiNiu.secretKey}")
    private String secretKey;//公共配置文件路径

    @Value("${qiNiu.bucket}")
    private String bucket;//公共配置文件路径


    /**
     * 查询所有赠品信息
     *
     * @param antPage
     * @return
     */
    @RequestMapping(value = "/queryAllGoods", method = RequestMethod.GET)
    @ResponseBody
    public ApiResultBean queryAllGoods(AntPage antPage,String name,String remark) {
        return goodsService.queryAllGoods(antPage,name,remark);
    }

    /**
     * 添加赠品
     *
     * @param goodsVo
     * @return
     */
    @RequestMapping(value = "/addGoods", method = RequestMethod.POST)
    @ResponseBody
    public ApiResultBean addGoods(GoodsVo goodsVo) {

        return goodsService.addGoods(goodsVo);
    }

    /**
     * 删除赠品
     *
     * @param goodsId
     * @return
     */
    @RequestMapping(value = "/deleteGoods", method = RequestMethod.POST)
    @ResponseBody
    public ApiResultBean deleteGoods(String goodsId) {

        return goodsService.deleteGoods(goodsId);
    }


    /**
     * 修改赠品信息
     *
     * @param goodsVo
     * @return
     */
    @RequestMapping(value = "/modifyGoods", method = RequestMethod.POST)
    @ResponseBody
    public ApiResultBean modifyGoods(GoodsVo goodsVo) {

        return goodsService.modifyGoods(goodsVo);
    }

    /**
     * 获取七牛token
     * @return
     */
    @GetMapping("/queryToken")
   /* @RequestMapping(value = "/queryToken", method = RequestMethod.GET)
    @ResponseBody*/
    public ApiResultBean queryToken() {
        ApiResultBean apiResultBean = new ApiResultBean();
        Auth auth = Auth.create(accessKey, secretKey);
        String upToken = auth.uploadToken(bucket);
        HashMap<String,String> hashMap=new HashMap<>();
        hashMap.put("token",upToken);
        apiResultBean.setData(upToken);
        return apiResultBean;
    }




}